package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.dto.OrdersDetailsDTO;
import com.woniuxy.mesboot.entity.MesOrdersdetail;
import com.woniuxy.mesboot.entity.ProType;
import com.woniuxy.mesboot.service.ProTypeService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 黑川
 * @version : 1.0
 * @Project : mes-boot
 * @Package : com.woniuxy.mesboot.controller
 * @ClassName : .java
 * @createTime : 2023/5/29 17:30
 * @Description :
 */
@RestController
@RequestMapping("/protype")
public class ProTypeController {
    @Resource
    private ProTypeService typeService;
    @PostMapping("queryAll")
    public Result queryAll(){
        List<ProType> list = typeService.selectAll();
        return Result.ok().data("list",list);
    }
    @PostMapping
    public Result add(@RequestBody ProType proType){
        int i = typeService.insertSelective(proType);
        if(i>0){
            return Result.ok("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }
    @GetMapping("{productTypeId}")
    public Result queryById(@PathVariable("productTypeId") Long id){
        ProType type = typeService.selectByPrimaryKey(id);
        return Result.ok().data("type",type);
    }
    @PutMapping
    public Result update(@RequestBody ProType proType){
        int i = typeService.updateByPrimaryKeySelective(proType);
        if(i>0){
            return Result.ok("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }
    @DeleteMapping("{productTypeId}")
    public Result delete(@PathVariable("productTypeId") Long id){
        int i = typeService.deleteByPrimaryKey(id);
        if(i>0){
            return Result.ok("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
}
